﻿using System;
using SharpSqlAnalyzer.nodes;
using SharpSqlAnalyzer.pp.processor.type.comm;
using SharpSqlAnalyzer.pp.utils;
using SharpSqlAnalyzer.stmt;

namespace SharpSqlAnalyzer.pp.processor.type.insert
{
	// Token: 0x0200023D RID: 573
	public class AppendLineAfterInsertTableNameProcessor : AbstractProcessor
	{
		// Token: 0x060012EF RID: 4847 RVA: 0x0031B980 File Offset: 0x00319B80
		public override void process(TParseTreeNode nodeArg)
		{
			TInsertSqlStatement tinsertSqlStatement = nodeArg as TInsertSqlStatement;
			TObjectNameList columnList = tinsertSqlStatement.ColumnList;
			this.processTableColumns(tinsertSqlStatement.TargetTable, columnList);
			if (tinsertSqlStatement.InsertIntoValues != null && tinsertSqlStatement.InsertIntoValues.Count > 0)
			{
				for (int i = 0; i < tinsertSqlStatement.InsertIntoValues.Count; i++)
				{
					TInsertIntoValue tinsertIntoValue = tinsertSqlStatement.InsertIntoValues[i];
					int length = SourceTokenOperator.curIndentLenVT(tinsertSqlStatement.startToken);
					SourceTokenOperator.removeWhitespaceAndReturnFromEnd(this.Option, tinsertIntoValue.startToken);
					SourceTokenOperator.addBefore(this.Option, tinsertIntoValue.startToken, SourceTokenOperator.createReturnSourceToken());
					SourceTokenOperator.addBefore(this.Option, tinsertIntoValue.startToken, SourceTokenOperator.createWhitespaceSourceToken(length));
					this.processTableColumns(tinsertIntoValue.Table, tinsertIntoValue.ColumnList);
				}
			}
		}

		// Token: 0x060012F0 RID: 4848 RVA: 0x0031BA48 File Offset: 0x00319C48
		private void processTableColumns(TTable table, TObjectNameList columnList)
		{
			if (columnList != null && columnList.size() > 0)
			{
				TSourceToken tsourceToken = SourceTokenSearcher.backforwardSearch(columnList.startToken, 3, "(");
				int length = SourceTokenOperator.curColumnNumberVT(table.startToken);
				SourceTokenOperator.removeWhitespaceAndReturnFromEnd(this.Option, tsourceToken);
				SourceTokenOperator.addBefore(this.Option, tsourceToken, SourceTokenOperator.createReturnSourceToken());
				SourceTokenOperator.addBefore(this.Option, tsourceToken, SourceTokenOperator.createWhitespaceSourceToken(length));
			}
		}
	}
}
